<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    // 数组转Map(二维数组)

    var arr = [1, 2, 3, 4];
    var obj = { a: 1, b: 2 };
    var div = document.createElement("div")

    // (1) 手动遍历设置
    // var list = [[100, 200], ["hello", "world"], [true, false], [null, undefined], [arr, arr], [obj, obj], [div, div]];

    // var m = new Map();
    // for (var i = 0; i < list.length; i++) {
    //     var item = list[i]; // [100, 200]
    //     var key = item[0];
    //     var val = item[1];
    //     m.set(key, val);
    // }
    // console.log(m);

    // (2) new Map() 直接接收二维数组
    var list = [[100, 200], ["hello", "world"], [true, false], [null, undefined], [arr, arr], [obj, obj], [div, div]];
    var m = new Map(list);
    console.log(m);


    // Map数据结构转二维数组
    // (1) 手动遍历转换
    var list = [];
    m.forEach((val, key) => {
        var subArr = [key, val];
        list.push(subArr);
    })
    console.log(list);

    // (2)  借助 Array.from()  ...
    var list = Array.from(m);
    console.log(list);

    var list = [...m];
    console.log(list);



</script>

</html>